/**
 * Created by Administrator on 2019/3/21.
 */
function addreclist($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q) {
    $scope.mater = {};
    /*//<option>赛特斯集团</option>
     <option>浩方信息</option>
     <option>赛特斯广东</option>*/
    $scope.compSelect = [
        {name: "赛特斯集团", code: "STSJT"},
        {name: "浩方信息", code: "HFXX"},
        {name: "赛特斯广东", code: "STSGD"}
    ]

    $scope.$watch("mater.projName", function (newValue, old, scope) {
        if (old && newValue) {
            if (newValue.indexOf(old) > -1) {
                nowProjName = newValue;
                scope.userProjSelect2 = scope.userProjSelect2.filter(isSaveProjName);
                if (scope.userProjSelect2.length) {
                    if (scope.userProjSelect2.length == 1) {
                        scope.mater.removedProjId = scope.userProjSelect2[0].projId;
                        scope.mater.removedProjName = scope.userProjSelect2[0].projName;
                    }
                }
                if (!scope.userProjSelect2 || scope.userProjSelect2.length == 0) {
                    scope.mater.removedProjId = "";
                    scope.mater.removedProjName = "";
                }
                return;
            }
        }

        //直接去数据库 查询
        CertusFormAjax.ajax("relatedProj", {param: newValue}, function (res) {
            scope.userProjSelect2 = res.data;
            if (scope.userProjSelect2) {
                if (scope.userProjSelect2.length == 1) {
                    scope.mater.removedProjId = scope.userProjSelect2[0].projId;
                    scope.mater.removedProjName = scope.userProjSelect2[0].projName;
                }
            }
        })
    })

    /*<option>南京</option>
     <option>北京</option>
     <option>上海</option>
     <option>广州</option>*/
    $scope.areaSelect = [
        {name: "南京", code: "NJ"},
        {name: "北京", code: "BJ"},
        {name: "上海", code: "SH"},
        {name: "广州", code: "GZ"},
    ]

    /*<option>采购</option>
     <option>退回</option>
     <option>外部购买</option>
     <option>其他</option>*/
    $scope.originTypeSelect = [
        {name: "采购", code: "CG"},
        {name: "退回", code: "TH"},
        {name: "外部购买", code: "WBGM"},
        {name: "其他", code: "QT"}
    ]

    $scope.originTypeChange = function (a) {
        for (var i in $scope.originTypeSelect) {
            if ($scope.originTypeSelect[i].code == a) {
                $scope.mater.originName = $scope.originTypeSelect[i].name;
            }
        }
    }

    /*<option>白酒</option>
     <option>红酒</option>
     <option>礼品</option>
     <option>其他</option>*/
    $scope.materNoSelect = [
        {name: "白酒", code: "BJ"},
        {name: "红酒", code: "HJ"},
        {name: "礼品", code: "LP"},
        {name: "其他", code: "QT"}
    ]

    $scope.materNoChange = function (a) {
        for (var i in $scope.materNoSelect) {
            if ($scope.materNoSelect[i].code == a) {
                $scope.mater.materTypeName = $scope.materNoSelect[i].name;
            }
        }
    }

    var picker2 = $('#caiTime').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if (result && !angular.isUndefined(result)) {
            $$scope.mater.purchaseTime = result;
            $$scope.$apply();
        }
    })

    $scope.confirmTo = function () {
        if (certusValidateNotnull()) {
            CertusJsonAjax.ajax("materSave", $scope.mater, function (res) {
                if (res.data == "success") {
                    layer.msg("添加成功");
                    history.back();
                }
            })
        }
    }
}

function selreclist($scope, $route, CertusFormAjax, CertusJsonAjax, $location, $http, $cookies, $routeParams, $q) {

    $$scope = $scope;
    $scope.search1 = {};
    var dataInit1 = CertusJsonAjax.dataInit("listMaterial", null, reclistColumns, "reclistContainer", "reclistToolBarContainer");

    //2
    $scope.search2 = {};

    $scope.searchFunc2 = function(){
        CertusJsonAjax.ajax("scalaTest",{},function(res){
            layer.msg(res.data);
        })
    }


    $scope.areaSelect = [
        {name: "请选择", code: ""},
        {name: "南京", code: "NJ"},
        {name: "北京", code: "BJ"},
        {name: "上海", code: "SH"},
        {name: "广州", code: "GZ"},
    ]
    //3
    $scope.search3 = {};
    var dataInit3 = CertusJsonAjax.dataInit("listMaterialPage", null, greclogColumns, "greclogContainer", "greclogToolBarContainer");
    $scope.searchFunc3 = function () {

        dataInit3.parameters = $scope.search3;
        dataInit3.refresh(true);
    }
    //第三个 列表 导出
    $scope.downloadFunc3 = function () {
        CertusFormAjax.download("downloadFunc3", "startTime=" + $scope.search3.startTime + "&endTime="
            + $scope.search3.endTime + "&comp=" + $scope.search3.comp + $scope.search3.comp + "&projName=" + $scope.search3.projName
            + "&userName=" + $scope.search3.userName + "&materName=" + $scope.search3.materName);

    }



}